﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.inventory {
    import flash.utils.*;

    public class BaseInventory {

        protected var m_storage:Dictionary;

        public function BaseInventory(_arg1:Object){
            this.m_storage = new Dictionary();
            super();
            this.loadObject(_arg1);
        }
        protected function loadObject(_arg1:Object):void{
            var _local2:String;
            var _local3:int;
            if ((((_arg1 == null)) || ((_arg1.storage == null)))){
                return;
            };
            for (_local2 in _arg1.storage) {
                _local3 = int(_arg1.storage[_local2]);
                this.m_storage[_local2] = _local3;
            };
        }
        public function isValidName(_arg1:String):Boolean{
            return (false);
        }
        public function getCapacity(_arg1:String):int{
            return (0);
        }
        protected function onDataChange(_arg1:String):void{
        }
        public function getSpareCapacity(_arg1:String):int{
            return ((this.getCapacity(_arg1) - this.getCount(_arg1)));
        }
        public function getCount(_arg1:String):int{
            if (this.m_storage[_arg1] != null){
                return (int(this.m_storage[_arg1]));
            };
            return (0);
        }
        public function getTotalCount():int{
            var _local2:int;
            var _local1:int;
            for each (_local2 in this.m_storage) {
                _local1 = (_local1 + int(_local2));
            };
            return (_local1);
        }
        public function getAddedCount(_arg1:Array):int{
            var _local3:String;
            var _local2:int;
            for each (_local3 in _arg1) {
                _local2 = (_local2 + this.getCount(_local3));
            };
            return (_local2);
        }
        public function add(_arg1:String, _arg2:int):Boolean{
            if (((((!(this.isValidName(_arg1))) || ((_arg2 <= 0)))) || ((this.getSpareCapacity(_arg1) < _arg2)))){
                return (false);
            };
            if (this.m_storage[_arg1] == null){
                this.m_storage[_arg1] = 0;
            };
            this.m_storage[_arg1] = (this.m_storage[_arg1] + _arg2);
            this.onDataChange(_arg1);
            return (true);
        }
        public function remove(_arg1:String, _arg2:int):Boolean{
            if (((((!(this.isValidName(_arg1))) || ((_arg2 <= 0)))) || ((_arg2 > this.getCount(_arg1))))){
                return (false);
            };
            this.m_storage[_arg1] = (this.m_storage[_arg1] - _arg2);
            if (this.m_storage[_arg1] == 0){
                delete this.m_storage[_arg1];
            };
            this.onDataChange(_arg1);
            return (true);
        }
        public function clear():Boolean{
            this.m_storage = new Dictionary();
            return (true);
        }

    }
}//package Classes.inventory 
